/*
// Definition for a Node.
class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
*/

class Solution {
public:
    vector<vector<int>> levelOrder(Node* root) {
        vector<vector<int>> res;
        if(root==nullptr){
            return res;
        }
        queue<Node*> que;
        que.push(root);
        while(!que.empty()){
            int n=que.size();
            vector<int> nodes;
            for(int i=1;i<=n;i++){
                Node* node=que.front();
                nodes.emplace_back(node->val);
                que.pop();
                for(Node* child :node->children){
                   que.push(child);
                }
            }
            res.emplace_back(nodes);
        }
        return res;
    }
};